package com.qhx.rtkcloud.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class StatusChange {
    public static  void main(String[] args) throws IOException {


        ServerSocket serverSocket = new ServerSocket(2019);
        Socket socket = serverSocket.accept();
        OutputStream outputStream = socket.getOutputStream();
        InputStream inputStream = socket.getInputStream();
        new Thread(() -> {
            byte[] bytes = new byte[1024];
            int length = -1;
          while (true)  {
              try {
                  if ((length = inputStream.read(bytes)) > -1) {
                      String str = new String(bytes, 0, length);
                      if (str.contains("queryNavModel")) {
                          outputStream.write("model:1".getBytes());
                          outputStream.flush();
                      }
                  }
              } catch (IOException e) {
                  throw new RuntimeException(e);
              }

          }

        }).start();

        new Thread(() -> {
            while (true) {
                Scanner scanner = new Scanner(System.in);
                String line =  scanner.nextLine();
                try {
                    outputStream.write("model:1".getBytes());
                    outputStream.flush();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }

                System.out.println(line);
            }
        }).start();


    }
}
